/* Replication Do-file for: Online Appendix: Unbreakable Legacies? Redistricting, Political Capital and Political Dynasties */
/* Version: v1.0 */
/* Date: May 2024 */
***********************************


***********************************
***********************************
* set path to data:
*cd ""
use onlineappendix_unbreaklegacies_replication_may2024.dta, clear

* install rd packages:
net install st0366_1, all replace force from(http://www.stata-journal.com/software/sj17-2)

***********************************
***********************************

* Analysis

***********************************
***********************************

***********************************
* set path to tables:
*cd ""
***********************************

* sumstats
* Table A1: Summary Statistics: Additional Dependent Variables, incl. Pre-Reform Constituency and Individual Incumbent Characteristics
sum minpopulation23 mintotalvotes23 mintotalelectors23  maxpopulation23 maxtotalvotes23 maxtotalelectors23   totalnrseats23 marginvote23 unopposed23 nrcompetitors23  raninsamenewconstid totaltenure loyaltogov retiredloyal, sep(0)

***********************************
* pre-treatment covs
* Table A2: Effect of Narrowly Redistricted Incumbents on Pre-Treatment Characteristics
foreach var of varlist liberal conservative seats_up age_pre arist elite rentier jr england scotland wales {
rdrobust `var' population, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
}

***********************************
* Robustness checks

* Table A3: Robustness: Placebo threshold, Incumbents, non-absorbed constituencies
foreach var of varlist future_relative immediatefuture_relative upto1918_relative retired raninParl23 reelect_new  partisanchange {
rdrobust `var'  population, c(50000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
}
* conditional on running
rdrobust reelect_new  population if raninParl23==1, c(50000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 

* Table A4: Robustness: Incumbents, non-absorbed constituencies boroughs of 1 seat only
preserve
keep if borough==1&seats_up==1
rdrobust future_relative  population, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
* show this in rdplot:
local lbandwidth = e(h_l)
local rbandwidth = e(h_r)
rdplot future_relative  population if population >= (15000-`lbandwidth')&population <= (15000+`rbandwidth'), c(15000)  p(1) kernel(triangular) binselect(qsmvpr)  graph_options(ylabel(0 (0.2) 1)  plotregion(lstyle(solid)  lcolor(black) ifcolor(white)) xtitle(Population) ytitle(Future relative) legend(off) yscale(range(0 1)) )  vce(cluster constituencyid1)
*graph export coefplot_above15_dynoutcomes_allsamples_boroughsonly1seat.png, replace
foreach var of varlist immediatefuture_relative upto1918_relative retired raninParl23 reelect_new partisanchange {
rdrobust `var'  population, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
}
* for reviewer 2:
rdrobust reelect_new  population if raninParl23==1, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
restore

* Table A5: Robustness: Incumbents, non-absorbed constituencies, excluding partisan changes
preserve
drop if partisanchange!=0
foreach var of varlist future_relative immediatefuture_relative upto1918_relative retired raninParl23 reelect_new  {
rdrobust `var'  population, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1)
}
* conditional on running
rdrobust reelect_new  population if raninParl23==1, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1)
*
* show this in rdplot:
rdrobust future_relative  population, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
local lbandwidth = e(h_l)
local rbandwidth = e(h_r)
rdplot future_relative  population if population >= (15000-`lbandwidth')&population <= (15000+`rbandwidth') & population>0, c(15000)  p(1) h(`lbandwidth' `rbandwidth') kernel(triangular)  binselect(qsmv) graph_options(xlabel(0 15000 35000) xtitle(Population) ytitle(Future relative) legend(off))  vce(cluster constituencyid1) 
*graph export coefplot_above15_dynoutcomes_partisancontrol.png, replace
restore

* Table A6: Effect of Narrowly Redistricted Incumbents on partisan change and Other Pre-Reform Constituency Characteristics
foreach var of varlist  minpopulation23 maxpopulation23 mintotalelectors23 maxtotalelectors23 mintotalvotes23 maxtotalvotes23 {
sum `var'
rdrobust `var' population, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
}
* Table A7: Long-term results
preserve
rdrobust labour_everafter85  population, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
restore
preserve
keep if partisanchange==0
rdrobust labour_everafter85  population, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
restore


***********************************
* set path to figures:
*cd ""
***********************************
* figures

graph box maxoldinnewpop, over(above15, relabel(1 "Pop < 15,000" 2 "Pop>=15,000")) box(1, fcolor(none) lcolor(black)) marker(1, mcolor(black)) ytitle(`"Max Pop"') graphregion(fcolor(white) ifcolor(white)) plotregion(ifcolor(white))

* density tests
rddensity population,  c(15000) kernel(triangular) bwselect(each) p(1) plot plot_grid(es) nomasspoints hist_width(1000 1000)
*graph export rddensity.png, replace

rddensity population,  c(50000) kernel(triangular)  bwselect(each) p(1) plot plot_grid(es) nomasspoints  hist_width(1000 1000) /*hist_n(9 38)*/
*graph export rddensity50.png, replace

* es bins
rdplot future_relative population, p(1) kernel(tr) c(15000) vce(cluster constituencyid1)  binselect(esmvpr) graph_options(xlabel(15000 250000 500000) ylabel(0 (0.2) 1)  plotregion(lstyle(solid)  lcolor(black) ifcolor(white)) xtitle(Population) ytitle(Future relative) legend(off) yscale(range(0 1)) xscale(range(0 60000))) save(fr_rdplot_esmv, replace) 
*graph export fr_rdplot_esmv.png, replace
* short es bins
rdrobust future_relative  population, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
* show this in rdplot:
local lbandwidth = e(h_l)
local rbandwidth = e(h_r)
rdplot future_relative population  if population >= (15000-`lbandwidth')&population <= (15000+`rbandwidth'), p(1) kernel(tr) c(15000) vce(cluster constituencyid1)   binselect(esmvpr) graph_options(title(Reduced Form, color(black)) legend(position(6)) xtitle(Population) ytitle(Future Relative)  plotregion(lstyle(solid)  lcolor(black) ifcolor(white))  ylabel(0 (0.2) 1) yscale(range(0 1))) save(fr_rdplot_esmv_short, replace) legend(off) vce(cluster constituencyid1)
*graph export fr_rdplot_esmv_short.png, replace

* qs bins
rdplot future_relative population, p(1) kernel(tr) c(15000) vce(cluster constituencyid1) binselect(qsmvpr)  graph_options(xlabel(15000 250000 500000) ylabel(0 (0.2) 1)  plotregion(lstyle(solid)  lcolor(black) ifcolor(white)) xtitle(Population) ytitle(Future relative) legend(off) yscale(range(0 1)) xscale(range(0 60000))) ///
 save(fr_rdplot_qsmv, replace)  legend(off) vce(cluster constituencyid1)
graph export fr_rdplot_qsmv.png, replace
* short qs bins
rdrobust future_relative  population, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1)
* show this in rdplot:
local lbandwidth = e(h_l)
local rbandwidth = e(h_r)
display `lbandwidth' " "  `rbandwidth' 
rdplot future_relative population  if population >= (15000-`lbandwidth')&population <= (15000+`rbandwidth'), p(1) kernel(tr) c(15000) vce(cluster constituencyid1)  binselect(qsmvpr) graph_options(title(Reduced Form, color(black)) legend(position(6))  plotregion(lstyle(solid)  lcolor(black) ifcolor(white))  ylabel(0 (0.2) 1) yscale(range(0 1)) xtitle(Population) ytitle(Future Relative)  graphregion(fcolor(white) lcolor(white)))  save(fr_rdplot_qsmv_short, replace) legend(off) vce(cluster constituencyid1)
graph export fr_rdplot_qsmv_short.png, replace

* main results figure
rdrobust future_relative  population, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1)
* show this in rdplot:
local lbandwidth = e(h_l)
local rbandwidth = e(h_r)
display `lbandwidth' " "  `rbandwidth' 
rdplot future_relative  population if population >= (15000-`lbandwidth')&population <= (15000+`rbandwidth'), c(15000)  p(1) kernel(triangular) binselect(qsmvpr)  graph_options(xlabel(0 5000 15000  50000) ylabel(0 (0.2) 1)  plotregion(lstyle(solid)  lcolor(black) ifcolor(white)) xtitle(Population) ytitle(Future relative) legend(off) yscale(range(0 1)) xscale(range(0 50000)))  vce(cluster constituencyid1)
*graph export rd_futurerelative_15_locallin_rdrobust.png, replace

* placebo figure
rdrobust future_relative  population, c(50000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
local lbandwidth = e(h_l)
local rbandwidth = e(h_r)
rdplot future_relative  population if population >= (50000-`lbandwidth')&population <= (50000+`rbandwidth') & population>0, c(50000)  p(1) h(`lbandwidth' `rbandwidth') kernel(triangular)  binselect(qsmvpr)  graph_options(xlabel(20000 50000 80000) ylabel(0 (0.2) 1)  plotregion(lstyle(solid)  lcolor(black) ifcolor(white)) xtitle(Population) ytitle(Future relative) legend(off) yscale(range(0 1)) xscale(range(20000 80000)))  vce(cluster constituencyid1)
*graph export rd_futurerelative_50_locallin_rdrobust.png, replace

* Table A4: Robustness: Incumbents, non-absorbed constituencies boroughs of 1 seat only
*RD robust 3a
preserve
keep if borough==1
rdrobust future_relative  population, c(15000) kernel(triangular) p(1) bwselect(mserd) vce(cluster constituencyid1) 
* show this in rdplot:
local lbandwidth = e(h_l)
local rbandwidth = e(h_r)
rdplot future_relative  population if population >= (15000-`lbandwidth')&population <= (15000+`rbandwidth'), c(15000)  p(1) kernel(triangular) binselect(qsmvpr)  graph_options(ylabel(0 (0.2) 1)  plotregion(lstyle(solid)  lcolor(black) ifcolor(white)) xtitle(Population) ytitle(Future relative) legend(off) yscale(range(0 1)) )  vce(cluster constituencyid1)
*graph export coefplot_above15_dynoutcomes_allsamples_boroughsonly.png, replace
restore
